package com.adams.log.dao.impl;

import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.xwork.StringUtils;
import org.springframework.stereotype.Repository;

import com.adams.access.db.bean.OptLog;
import com.adams.access.db.dao.hibernate.HibernateDao;
import com.adams.log.dao.OptLogDao;
import com.adams.utils.Page;

/**
 * 
 * 
 * File Name : OptLogDaoImpl.java
 * 
 * @Description : 后台日志管理数据操作接口，提供对用户的增、查功能
 * @author 902990封文进
 */
@Repository("optLogDao")
public class OptLogDaoImpl extends HibernateDao<OptLog, Long> implements
		OptLogDao
{

	/**
	 * 
	 * Description : 根据操作员和操作时间查询日志
	 * 
	 * @param page
	 * @param operator
	 * @param operateTime
	 * @return Page<OptLog>
	 * 
	 */
	public Page<OptLog> queryByCondition(Page<OptLog> page, String operator,
			Date operateTime)
	{
		StringBuilder sb = new StringBuilder();
		if (StringUtils.isNotEmpty(operator))
		{
			sb.append("and operator like '%" + operator + "%' ");
		}
		if (operateTime != null)
		{
			sb.append("and operateTime >= '"
					+ DateFormatUtils.format(operateTime, "yyyy-MM-dd")
					+ " 00:00:00" + "' and operateTime <= '"
					+ DateFormatUtils.format(operateTime, "yyyy-MM-dd")
					+ " 23:59:59" + "'");
		}
		return (Page<OptLog>) queryPage(page, "from OptLog where 1=1 "
				+ sb.toString() + " order by operateTime desc");
	}

}
